var fs=require('fs')
var https = require("https")
var http = require("http")

var obj = {
    "home":function(req,res){
        res.write("home")
        res.end()
    },
    "about":function(req,res){
        res.write("about")
        res.end()
    },
    "other":function(req,res){
        res.write("other")
        res.end()
    },
    "index":function(req,res){
        fs.readFile('./index.html',(err,data)=>{
            res.write(data)
            res.end()
        })
    },
    "data":function(req,res){
        fs.readFile('./data.json',(err,data)=>{
            res.write(data)
            res.end()
        })
    },
    "douban":function(req1,res1){
        const options = {
            hostname:'api.douban.com',
            post:443,
            path:"/v2/book/isbn/9787010009230?apikey=0df993c66c0c636e29ecbb5344252a4a",
            method:'GET'
        }
        
        
        var str = ''
        var str1= ''
        const req = https.request(options,(res)=>{
            // data是对数据进行接受
            res.on('data',(d)=>{ 
                str += d
            })
            // end是对数据进行处理
            res.on('end',(d)=>{
                str1 = str
                res1.end(str1)
            })
        })
        
        req.on('error',(e)=>{
            console.error(e)
        })
        
        req.end()
    }
}
module.exports = obj;